package com.inspur.cloud.service.dataspace;

import com.inspur.cloud.dao.dataspace.UserDao;
import com.inspur.cloud.entity.dataspace.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    public void save(UserEntity userEntity){
        userDao.save(userEntity);
    }
    public void delete(UserEntity userEntity){
        userDao.delete(userEntity);
    }
    public List<UserEntity> findAll(){
        return userDao.findAll();
    }
    public UserEntity findUserByName(String name){
        return userDao.findUserByName(name);
    }
    public List<UserEntity> findByNameIn(List<String> nameList){
        return userDao.findByNameIn(nameList);
    }
    public  UserEntity findUserById(int id){
        return userDao.findUserById(id);
    }
    public Page<UserEntity> findAll(Specification<UserEntity> specification, Pageable pageable){
        return userDao.findAll(specification,pageable);
    }
    //用户失败次数更新调度任务
    @Transactional(transactionManager = "transactionManagerDataspace")
    public void updateUserFailureTimes(){
        userDao.updateUserFailureTimes();
    }
    //超级管理员次数更新调度任务
    @Transactional(transactionManager = "transactionManagerDataspace")
    public void updateAdminFailureTimes(){
        userDao.updateAdminFailureTimes();
    }
    public List<UserEntity> findByFailureTimesGreaterThanEqualAndParentId(Integer failureTimes, Integer parentId){
        return userDao.findByFailureTimesGreaterThanEqualAndParentId(failureTimes,parentId);
    }
    public List<UserEntity> findByFailureTimesGreaterThanEqual(Integer failureTimes){
        return userDao.findByFailureTimesGreaterThanEqual(failureTimes);
    }
    public List<UserEntity> findByParentId(Integer parentId){
        return userDao.findByParentId(parentId);
    }
    public List<Integer> findIdByParentId(Integer parentId){
        return userDao.findIdByParentId(parentId);
    }
    public List<UserEntity> findByIdIn(List<Integer> idList){
        return userDao.findByIdIn(idList);
    }
}
